import instance from "@/utils/http";

// 获取轮播图数据
export function getLoop(number) {
    return instance.get(`/api/weChat/applet/course/banner/list?number=${number}`)
}
// 获取课程列表
export function getList(type, pageNum, pageSize) {
    let params = new URLSearchParams
    params.append("type", type)
    params.append("pageNum", pageNum)
    params.append("pageSize", pageSize)
    return instance.post(`/api/weChat/applet/course/list/type`, params)
}
// 获取课程分类信息
export function getClassifyList() {
    return instance.post(`/api/weChat/applet/subject/list`, { enable: 1 })
}
// 获取某个课程的详情信息
export function getCourseDetail(courseId) {
    return instance.get(`/api/pc/course/detail/${courseId}`)
}
/* 获取头条精选 */
export function getHeadlineList(params) {
    return instance.post(`/api/weChat/applet/article/list?pageNum=1&pageSize=5`,params)
}
// 获取底部信息
export function getFooterInfo() {
    let params = new URLSearchParams
    params.append("dictType", "blogroll")
    params.append("pageNum", "1")
    params.append("pageSize", "5")
    params.append("orderByColumn", "dictSort")
    params.append("isAsc", "asc")


    params.append("Content-Type", "application/x-www-form-urlencoded")
    return instance.post('/api/system/dict/data/list/open', params)
}

// 获取课程评论
export function getCourseComment(courseId, pageSize, pageNum) {

    return instance.get(`/api/pc/comment/commentList/course/${courseId}?pageNum=${pageNum}&pageSize=${pageSize}`)
}
//登录
export function getLoginInfo(username, password) {
    let params = new URLSearchParams
    params.append("username", username)
    params.append("password", password)
    params.append("rememberMe", false)
    return instance.post(`/api/pcUser/login`, params)
}
// 获取搜索结果
export function getSearchResult(pageNum, pageSize, type, subjectId, keyword, courseType) {
    const url = `/api/pc/course/search/keyword?pageNum=${pageNum}&pageSize=${pageSize}&type=${type}&keyword=${keyword}&subjectId=${subjectId}&courseType=${courseType}`;
    return instance.get(url)
}
// 用户登出
export function logout(){
    return instance.get(`/api/pcUser/logout`)
}

// 获取验证码
export function  getCheckCode(mobile){
    return instance.get(`/api/pcUser/login/send/code/${mobile}`)

}

// 获取用户信息
export function getLoginUserInfo(){
    return instance.get(`/api/pcUser/login-user/info`);
}
// 获取购物车信息
export function getUserShoppingCartInfo(status){
    return instance.get(`/api/weChat/applet/shoppingCart/my/list?status=${status}`);
}

// 删除购物车课程
export function deleteChartCourse(shoppingCartId){
    return instance.get(`/api/weChat/applet/shoppingCart/remove/${shoppingCartId}`)
}
// 添加购物车课程
export function addChartCourse(courseId){
    return instance.get(`/api/weChat/applet/shoppingCart/join/shoppingCart/${courseId}`)
}
// 获取直播课程
export function getLiveCourseInfo(pageNum, pageSize){
    // /api/pc/liveCourseInfo/list?pageSize=4&pageNum=1
    return instance.post(`/api/pc/liveCourseInfo/list?pageSize=${pageSize}&pageNum=${pageNum}`)
}
// 获取销量排行榜的课程信息
export function getSellingBestCourseInfo(){
    // /api/best-selling/course/list
    return instance.get(`/api/best-selling/course/list`)
}